#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <algorithm>
#include <map>
#include <climits>


using namespace std;


struct TreeNode {
    int val;
    TreeNode *left;
    TreeNode *right;
    TreeNode() : val(0), left(nullptr), right(nullptr) {}
    TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
    TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}
};

class Solution {
public:
    void flatten(TreeNode* root) {
        if(nullptr==root){
            return ;
        }
        flatten(root->left);
        flatten(root->right);
        TreeNode *l=root->left,*r=root->right,*p=nullptr;
        root->right=root->left;
        root->left=nullptr;
        p=root;
        while(p->right!=nullptr)p=p->right;
        p->right=r;
    }
};

int main(){




    return 0;
}